package com.cn;
import javax.servlet.MultipartConfigElement;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
import org.springframework.remoting.caucho.HessianProxyFactoryBean;

import com.cn.sys.service.ScheduleJobLogService;
import com.cn.sys.service.ScheduleJobService;
import com.cn.sys.service.SysRoleService;
import com.cn.utils.ConfigConstant;
//(scanBasePackages="com.cn.controller") 
@SpringBootApplication
@MapperScan("com.cn.sys.dao")
//@ImportResource({"classpath:dubbo-web.xml"})
public class Application extends SpringBootServletInitializer  {

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
		
//		ConfigurableApplicationContext run = SpringApplication.run(Application.class, args);
//		
//		SysRoleService service = run.getBean(SysRoleService.class);
//		service.findPage(0, 10, null);
		
	}
//	
	@Autowired
	private ConfigConstant constant;
	
	
	@Bean
	public HessianProxyFactoryBean getSysRoleService() {
		HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
		factory.setServiceUrl(constant.getSYS_SERVICE_URL()+"SysRoleService");
		factory.setOverloadEnabled(true); 
		factory.setServiceInterface(SysRoleService.class);
		return factory;
	}
	
	@Bean
	public HessianProxyFactoryBean getScheduleJobLogService() {
		HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
		factory.setServiceUrl(constant.getTASK_SERVICE_URL()+"ScheduleJobLogService");
		factory.setServiceInterface(ScheduleJobLogService.class);
		return factory;
	}
//	
	@Bean
	public HessianProxyFactoryBean getScheduleJobService() {
		HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
		factory.setServiceUrl(constant.getTASK_SERVICE_URL()+"ScheduleJobService");
		factory.setServiceInterface(ScheduleJobService.class);
		return factory;
	}

	
	// 文件上传限制
	@Bean
	public MultipartConfigElement multipartConfigElement() {
		MultipartConfigFactory factory = new MultipartConfigFactory();
		// 设置文件大小限制 ,超出设置页面会抛出异常信息，
		// 这样在文件上传的地方就需要进行异常信息的处理了;
		factory.setMaxFileSize("2560KB"); // KB,MB
		/// 设置总上传数据总大小
		factory.setMaxRequestSize("5120KB");
		// Sets the directory location where files will be stored.
		// factory.setLocation("路径地址");
		return factory.createMultipartConfig();
	}
	
}
